var wxCharts = require('../../../../utils/charts.js');
Page({
  data: {
    wz: '男女比例'
  },
  qh: function() {
    var that = this;
    if (that.data.wz == '男女比例') {
      that.setData({
        wz: '到校比例'
      })
      var pieChart = new wxCharts({
        animation: true,
        canvasId: 'pieCanvas',
        type: 'pie',
        series: [{
          name: '男生',
          data: that.data.boy,
        }, {
          name: '女生',
          data: that.data.all - that.data.boy,
        }],
        width: that.data.windowWidth,
        height: 300,
        dataLabel: true,
      });
    } else {
      that.onLoad()
    }
  },
  onLoad: function(options) {
    var that = this;
    wx.request({
      url: 'https://welcome.gongxueyun.com/welcome/yingxin/qdtj.php',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      success: function(res) {
        console.log(res)
        that.setData({
          wz: '男女比例',
          qd: res.data.qd,
          boy: res.data.boy,
          all: res.data.all
        })
        var pieChart = new wxCharts({
          animation: true,
          canvasId: 'pieCanvas', 
          type: 'pie',
          series: [{
            name: '已到校签到　　　　　　',
            data: that.data.qd,
          }, {
            name: '未到校签到　　　　　',
            data: that.data.all - that.data.qd,
          }],
          width: windowWidth,
          height: 300,
          dataLabel: true,
        });
      }
    })
    var windowWidth = 320;
    try {
      var res = wx.getSystemInfoSync();
      windowWidth = res.windowWidth;
      that.setData({
        windowWidth: windowWidth
      })
    } catch (e) {
      console.error('getSystemInfoSync failed!');
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})